package function;

import java.util.function.Consumer;
import java.util.function.Function;

/**
 * @Auther Jun jie Yi
 * @Date 14:32 2021/6/27
 */
public class ZhihaoTest {
    public static void main(String[] args) {
        new ZhihaoTest().test();
    }
    //Function 中两个泛型对应的一个是传入值类型，二个是返回值类型i -> i.getN1() - i.getN2()
    public void test() {
        Function<Numbers, Integer> test1 = new Function<Numbers, Integer>() {
            @Override
            public Integer apply(Numbers i) {
                return i.getN1() - i.getN2();
            }
        };
        Function<Numbers, Integer> test2 = i -> i.getN1() * i.getN2();
        Consumer<Numbers> test3 = i -> {Integer a = i.getN1() - i.getN2();System.out.println(a);};

        System.out.println(calculate(test1, 111, 5));
//        System.out.println(calculate(test2, 111, 5));
//          calculate1(test3, 111, 5);
    }

    public static Integer calculate(Function<Numbers, Integer> test, Integer number1, Integer number2) {
        Numbers n = new Numbers();
        n.setN1(number1);
        n.setN2(number2);
        return test.apply(n);
    }

    public static void calculate1(Consumer<Numbers> test3, Integer number1, Integer number2) {
        Numbers n = new Numbers();
        n.setN1(number1);
        n.setN2(number2);
        test3.accept(n);
    }
}

class Numbers {
    private Integer n1;
    private Integer n2;
    private Integer n3;

    public Numbers(Integer n1, Integer n2, Integer n3) {
        this.n1 = n1;
        this.n2 = n2;
        this.n3 = n3;
    }

    public Numbers() {
    }

    public Integer getN1() {
        return n1;
    }

    public void setN1(Integer n1) {
        this.n1 = n1;
    }

    public Integer getN2() {
        return n2;
    }

    public void setN2(Integer n2) {
        this.n2 = n2;
    }

    public Integer getN3() {
        return n3;
    }

    public void setN3(Integer n3) {
        this.n3 = n3;
    }
}
